﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;

public partial class Controls_ContactUs_ctrContactUs : System.Web.UI.UserControl
{
    private int nCurrentLang = Support.GetCurrentLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetLabel();
            ValidateControl();
            BindDataToDay();
            BindDataToMonth();
            BindDataToYear();
            BindDataCountry();
            BindData();
        }
    }
    private void SetLabel()
    {
        lblContact.Text = MultipleLanguage.CONTACT[nCurrentLang - 1].ToUpper();
        lblEmail.Text = MultipleLanguage.EMAIL[nCurrentLang - 1];
        lblFullName.Text = MultipleLanguage.FULLNAME[nCurrentLang - 1];
        lblInputRequire.Text = MultipleLanguage.INPUTREQUIRE[nCurrentLang - 1];
        lblTelephone.Text = MultipleLanguage.TELEPHONE[nCurrentLang - 1];
     
        lblAdult.Text = MultipleLanguage.LBLADULT[nCurrentLang - 1];
        lblChildren.Text = MultipleLanguage.LBLCHILD[nCurrentLang - 1];
        lblCountry.Text = MultipleLanguage.LBL_COUNTRY[nCurrentLang - 1];
        lblNumberOfTraveller.Text = MultipleLanguage.LBL_NUMBEROFTRAVELLERS[nCurrentLang - 1];
        lblMainContent.Text = MultipleLanguage.LBL_YOURMESSAGE[nCurrentLang - 1];
        lblTravelDate.Text = MultipleLanguage.LBL_TRAVELDATE[nCurrentLang - 1];
        

        StaticPages objStaticPage = new StaticPages();
        objStaticPage.LoadById(Config.COUNTACTID);
        switch (nCurrentLang)
        {
            case 1:
                ltrIntroduce.Text = objStaticPage.Data.PageContent1;
                break;
            case 2:
                ltrIntroduce.Text = objStaticPage.Data.PageContent2;
                break;
            case 3:
                ltrIntroduce.Text = objStaticPage.Data.PageContent3;
                break;
        }
    }
    private void ValidateControl()
    {
        revAdult.ErrorMessage = MessagesValidate.ADULTS_NUMBER[nCurrentLang - 1];
        revChildren.ErrorMessage = MessagesValidate.CHILDREN_NUMBER[nCurrentLang - 1];
        revEmail.ErrorMessage = MessagesValidate.Setting_EMAIL_WRONG[nCurrentLang-1];
        revNumberOfTraveller.ErrorMessage = MessagesValidate.NUMBEROFTRAVELLER_NUMBER[nCurrentLang - 1];
        rfvFullName.ErrorMessage = MessagesValidate.Setting_FULLNAME_EMPTY[nCurrentLang - 1];
        rfvEmail.ErrorMessage = MessagesValidate.EMAIL_EMPTY[nCurrentLang - 1];
        rfvMainContent.ErrorMessage = MessagesValidate.YOURMESSAGE_EMPTY[nCurrentLang - 1];
    }
    private void BindDataCountry()
    {
        DataTable dtbCustomerCountry = new DataTable();
        CustomerCountry objCustomerCountry = new CustomerCountry();
        dtbCustomerCountry = objCustomerCountry.GetALL();

        ddlCountry.DataSource = dtbCustomerCountry;
        ddlCountry.DataValueField = "CountryID";
        switch (nCurrentLang)
        {
            case 1:
                ddlCountry.DataTextField = "CountryName1";
                break;
            case 2:
                ddlCountry.DataTextField = "CountryName2";
                break;
            case 3:
                ddlCountry.DataTextField = "CountryName3";
                break;
        }
        ddlCountry.DataBind();
    }
   
    private void ClearForm()
    {
        txtEmail.Text = string.Empty;
        txtFullName.Text = string.Empty;
        txtMainContent.Text = string.Empty;
        txtTelephone.Text = string.Empty;
    }
    private void BindDataToDay()
    {
        for (int i = 0; i < 31; i++)
        {
            ListItem item;
            if ((i + 1) < 10)
                item = new ListItem((i + 1).ToString(), "0" + (i + 1).ToString(), true);
            else
                item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlTravelDay.Items.Add(item);
        }
    }
    private void BindDataToMonth()
    {
            ListItem item1;
            item1 = new ListItem(MultipleLanguage.MONTH1[nCurrentLang - 1], "01", true);
            ddlTravelMonth.Items.Add(item1);

            ListItem item2;
            item2 = new ListItem(MultipleLanguage.MONTH2[nCurrentLang - 1], "02", true);
            ddlTravelMonth.Items.Add(item2);

            ListItem item3;
            item3 = new ListItem(MultipleLanguage.MONTH3[nCurrentLang - 1], "03", true);
            ddlTravelMonth.Items.Add(item3);

            ListItem item4;
            item4 = new ListItem(MultipleLanguage.MONTH4[nCurrentLang - 1], "04", true);
            ddlTravelMonth.Items.Add(item4);


            ListItem item5;
            item5 = new ListItem(MultipleLanguage.MONTH5[nCurrentLang - 1], "05", true);
            ddlTravelMonth.Items.Add(item5);

            ListItem item6;
            item6 = new ListItem(MultipleLanguage.MONTH6[nCurrentLang - 1], "06", true);
            ddlTravelMonth.Items.Add(item6);

            ListItem item7;
            item7 = new ListItem(MultipleLanguage.MONTH7[nCurrentLang - 1], "07", true);
            ddlTravelMonth.Items.Add(item7);

            ListItem item8;
            item8 = new ListItem(MultipleLanguage.MONTH8[nCurrentLang - 1], "08", true);
            ddlTravelMonth.Items.Add(item8);

            ListItem item9;
            item9 = new ListItem(MultipleLanguage.MONTH9[nCurrentLang - 1], "09", true);
            ddlTravelMonth.Items.Add(item9);

            ListItem item10;
            item10 = new ListItem(MultipleLanguage.MONTH10[nCurrentLang - 1], "10", true);
            ddlTravelMonth.Items.Add(item10);

            ListItem item11;
            item11 = new ListItem(MultipleLanguage.MONTH11[nCurrentLang - 1], "11", true);
            ddlTravelMonth.Items.Add(item11);

            ListItem item12;
            item12 = new ListItem(MultipleLanguage.MONTH12[nCurrentLang - 1], "12", true);
            ddlTravelMonth.Items.Add(item12);

         
    }
    private void BindDataToYear()
    {
        for (int i = 2011; i < 2020; i++)
        {
            ListItem item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlTravelYear.Items.Add(item);
        }
    }
    protected void BindData()
    {
        ContactOffice ojbContactOffice = new ContactOffice();
        ojbContactOffice.LoadById(Config.CONTACT_DEFAULT);
    }
    protected void btnSend_Click(object sender, ImageClickEventArgs e)
    {
        Contacts objContact = new Contacts();
        objContact.Data.Email = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtEmail.Text.Trim()));
        objContact.Data.Telephone = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtTelephone.Text.Trim()));
        objContact.Data.Fullname = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtFullName.Text.Trim()));
        objContact.Data.MainContent = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtMainContent.Text.Trim()));
        objContact.Data.Status = 0;
        objContact.Data.CreatedDate = ConvertData.ConvertDatetimeToInt(DateTime.Today);
        objContact.Data.SendToOffice = 0;
        objContact.Data.Adult = ConvertData.ConvertToInt(txtAdult.Text);
        objContact.Data.Children = ConvertData.ConvertToInt(txtChildren.Text);
        objContact.Data.CountryID = ConvertData.ConvertToInt(ddlCountry.SelectedValue);
        objContact.Data.NumberOfTraellers = ConvertData.ConvertToInt(txtNumberOfTraveller.Text);
        objContact.Data.TravelDate = ConvertData.ConvertDateStringToInt(ddlTravelDay.Text + "/" + ddlTravelMonth.SelectedValue + "/" + ddlTravelYear.SelectedValue);
        objContact.Data.SendToOffice = 0;

        int nResult = objContact.Insert();
        int iCurrentLang = Support.GetCurrentLanguage();
        if (nResult > 0)
        {
            Alert1.ShowMessage(1, MultipleLanguage.CONTACT_SENT[iCurrentLang - 1]);
            ClearForm();
        }
        else { Alert1.ShowMessage(2, MultipleLanguage.CONTACT_SEND_FAIL[iCurrentLang - 1]); }
    }
}